from tensorflow.keras.models import load_model
import os
import numpy as np
from PIL import Image

# Defined param
images_path = '../images'
model_path = '../saved_models'
# model_name = 'keras_cifar10_trained_model.h5'
model_name = 'keras_cifar10_trained_model_adam.h5'

# Load model
model = load_model(os.path.join(os.getcwd(),model_path,model_name))

classes = ["飞机","汽车","鸟","猫","鹿","狗","青蛙","马","船","货车"]
images = ['ma.jpeg', 'dog.jpeg','qingwa.jpg','chuan.jpg']

arr = []
for image_name in images:
    print(image_name)
    im = Image.open(os.path.join(images_path, image_name))
    im_arr = im.resize((32, 32))
    arr.append(np.array(im_arr))
im_array = np.array(arr)
print(im_array.shape)

y_preu = model.predict(im_array.astype('float') / 255)
#
out_data = np.argmax(y_preu, axis=1)

# 结果
for i in range(len(out_data)):
    print("图片名称:{},所属的类别:{}".format(images[i],classes[out_data[i]]))
